# Contributor: kpcyrd <git@rxv.cc>
# Maintainer: kpcyrd <git@rxv.cc>
pkgname=rekor
pkgver=0.5.0
pkgrel=3
pkgdesc="Signature transparency log"
url="https://github.com/sigstore/rekor"
arch="all"
license="Apache-2.0"
makedepends="go"
subpackages="$pkgname-server
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
options="net"
source="$pkgname-$pkgver.tar.gz::https://github.com/sigstore/rekor/archive/v$pkgver.tar.gz"

export GOFLAGS="$GOFLAGS -trimpath -mod=readonly -modcacherw -ldflags=-X=github.com/sigstore/rekor/pkg/api.GitVersion=v$pkgver"

build() {
	go build -o cmd/rekor-cli/rekor-cli cmd/rekor-cli/main.go
	go build -o cmd/rekor-server/rekor-server cmd/rekor-server/main.go

	mkdir -p completions
	cmd/rekor-cli/rekor-cli completion bash > completions/rekor-cli.bash
	cmd/rekor-cli/rekor-cli completion zsh > completions/_rekor-cli
	cmd/rekor-cli/rekor-cli completion fish > completions/rekor-cli.fish

	cmd/rekor-server/rekor-server completion bash > completions/rekor-server.bash
	cmd/rekor-server/rekor-server completion zsh > completions/_rekor-server
	cmd/rekor-server/rekor-server completion fish > completions/rekor-server.fish
}

check() {
	go test -v ./...
}

package() {
	install -Dm755 "$builddir/cmd/rekor-cli/rekor-cli" "$pkgdir/usr/bin/rekor-cli"

	install -Dm644 "$builddir/completions/rekor-cli.bash" \
		"$pkgdir/usr/share/bash-completion/completions/rekor-cli"
	install -Dm644 "$builddir/completions/_rekor-cli" \
	    "$pkgdir/usr/share/zsh/site-functions/_rekor-cli"
	install -Dm644 "$builddir/completions/rekor-cli.fish" \
		"$pkgdir/usr/share/fish/completions/rekor-cli.fish"

	install -Dm644 "$builddir/completions/rekor-server.bash" \
		"$pkgdir/usr/share/bash-completion/completions/rekor-server"
	install -Dm644 "$builddir/completions/_rekor-server" \
	    "$pkgdir/usr/share/zsh/site-functions/_rekor-server"
	install -Dm644 "$builddir/completions/rekor-server.fish" \
		"$pkgdir/usr/share/fish/completions/rekor-server.fish"
}

server() {
	pkgdesc="Signature Transparency Log (server)"
	install -Dm755 "$builddir/cmd/rekor-server/rekor-server" "$subpkgdir/usr/bin/rekor-server"
}

sha512sums="
71850efb03bb3d8e44c17211d76f341739bbc684a2bc88fcafe8312e4f4deb7265c867148b14528cd44b0677be9db15d51e364bc2f5a9fc8b07b9720c8cd6273  rekor-0.5.0.tar.gz
"
